{% extends "technological/base.html" %}

{% block page_link %}
    <script src="../../static/technological/js/approve.js"></script>
    <link rel="stylesheet" href="../../static/technological/css/style.css">
    <script src="../../static/public_file/js/wangEditor.min.js" type="text/javascript" charset="UTF-8"></script>
{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }
        .basic-tabs{
            box-shadow: 0 1.5px 0 0 #1E90FF;
            color: #1E90FF;
        }
        .basic{
            width: 8%;height: 40px;line-height: 40px;text-align: center;display: inline-block;vertical-align: top;cursor: pointer;
        }
        .input-style{
            display: inline-block;
            width: 73%;
            height: 35px;
            border-radius: 7px;
            font-size: 14px;
            padding-left: 1%;
            border: #cfcfcf solid 1px;
            margin-left: 1%;
        }

        .textarea-style{
            display: inline-block;
            width: 73%;
            border-radius: 7px;
            font-size: 14px;
            padding-left: 1%;
            border: #cfcfcf solid 1px;
            margin-left: 1%;
        }
        .file {
            position: relative;
            display: inline-block;
            background: #D0EEFF;
            border: 1px solid #99D3F5;
            border-radius: 4px;
            padding: 4px 12px;
            overflow: hidden;
            color: #1E88C7;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
        }
        .file input {
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }
        .halving_line{
            width: 80%;
            border: #cfcfcf solid 0.5px;
            margin-left: 2%;
        }
        .label_tag{
            width: 100px;
            text-align: right;
            vertical-align: top;
            font-size: 14px;
            line-height: 35px;
        }
        .add-station{
            width: 60%;height: 35px;background: #0070c1;border-color: #c5dbec;color: #ffffff;
        }
        tr{
            height: 35px;
        }
        th{
            text-align: center;
        }
        table {
            table-layout: fixed;
        }
        td:first-child, th:first-child {
            position:sticky;
            left:0; /* 首行永远固定在左侧 */
            z-index:1;
        }
        thead tr th {
            position:sticky;
            top:0; /* 列首永远固定在头部  */
            background-color: #78C3F3;
            color: #00688B;
        }
        th:first-child{
            z-index:2;
        }
        .model_li{
            color: #3f414d;
            width: 25%;
            cursor: pointer;
            display: none;
        }
        .editor-none{
            display: none;
        }
        .editor-block{
            display: inline-block;
        }
    </style>
{% endblock %}



{% block right_content %}
    <div class="headline">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
            <a href="#" style="color: #0b0b0b;">
                <i class="iconfont icon-shenpi"></i>
                <span> 审批详情</span>
            </a>
        </div>

        <div style="width: 7%;text-align: center;height: 100%;line-height: 40px;float: right;margin-right: 2%;">
            <button onclick="examine(2)" style="height: 30px;width: 90%" type="button" class="btn btn-danger add-station1">驳回</button>
        </div>

        <div style="width: 7%;text-align: center;height: 100%;line-height: 40px;float: right;">
            <button style="height: 30px;width: 90%;background: #0070c1;color: #ffffff;border-radius: 3px" id="add_station" type="button" class="btn btn-default add-station" onclick="examine(3)">通过</button>
        </div>
    </div>


    <!-- 表单 -->
    <div id="menu_from" style="width: 100%;height: 88%;overflow: auto;margin-top: 0.2%;position: relative;">
        <h3 id="form_name" style="text-align: center;font-size: 20px;margin-top: 1%;"></h3>

        <div style="width: 95%;margin-left: 2.5%;margin-top: 1%;background: white;height: 40px;padding-left: 0.5%;line-height: 40px;">
            基本信息
        </div>

        <div style="border: #CFCFCF solid 0.5px;width: 95%;margin-left: 2.5%;margin-top: 1%;padding: 1%;">
            <div>
                <label for="" class="label_tag">申请人：</label>
                <input id="proposer" type="text" class="input-style" style="width: 32%;" disabled>

                <label for="" class="label_tag">部门：</label>
                <input id="department" type="text" class="input-style" style="width: 32%;" disabled>
            </div>

            <div style="margin-top: 1%;">
                <label for="" class="label_tag">申请时间：</label>
                <input id="now_time" type="text" class="input-style" style="width: 74.5%;" disabled>
            </div>
        </div>

        <div style="width: 95%;margin-left: 2.5%;margin-top: 1%;background: white;height: 40px;padding-left: 0.5%;line-height: 40px;">
            申请详情
        </div>

        <form id="menu_from_1" style="border: #CFCFCF solid 0.5px;width: 95%;margin-left: 2.5%;margin-top: 1%;">

        </form>

        <div style="width: 95%;margin-left: 2.5%;margin-top: 1%;background: white;height: 40px;padding-left: 0.5%;line-height: 40px;">
            <label>附件： </label>
            <a href="javascript:;" class="file" style="vertical-align:middle;">
                <i class="iconfont icon-upload"></i>
                上传附件
                <input type="file" name="accessory" id="accessory" onchange="upload_accessory()">
            </a>
        </div>

        <div style="border: #CFCFCF solid 0.5px;width: 95%;margin-left: 2.5%;height: 100px;margin-top: 1%;overflow: auto;">
            <div style="display: inline-block;vertical-align: top;width: 100%;">
                <table class="table table-hover table-bordered" style="border-collapse: collapse;width: 100%;">
                    <thead>
                        <tr>
                            <th scope="col" style="width: 3%;">
                                <input type="checkbox" onclick="check_all_not()" id="check_all">
                            </th>
                            <th scope="col" style="width: 8%;">序号</th>
                            <th scope="col" style="width: 30%;">文件名称</th>
                            <th scope="col" style="width: 8%;">文件大小</th>
                            <th scope="col" style="width: 15%;">上传时间</th>
                            <th scope="col" style="width: 5%;">操作</th>
                        </tr>
                    </thead>
                    <tbody style="overflow: auto;" id="t_table"></tbody>
                </table>
            </div>
        </div>

        <div onclick="wangEditor_show()" style="width: 95%;margin-left: 2.5%;margin-top: 1%;background: white;height: 40px;padding-left: 0.5%;line-height: 40px;cursor: pointer;">
            <i class="iconfont icon-yijianfankui"></i>
            <span> 审批意见</span>
        </div>


        <div id="wangEditor" style="width: 95%;margin-left: 2.5%;">
            <div id="summernote" style="width: 100%;display: inline-block;vertical-align: top;"></div>
        </div>



        <div style=";width: 95%;margin-left: 2.5%;height: 100px;margin-top: 1%;">

        </div>

    </div>

{% endblock %}

{% block script %}
    <script type="text/javascript" src="../../static/public_file/other/jquery.js"></script>
    <script type="text/javascript" src="../../static/public_file/js/GooFunc.js"></script>
    <script type="text/javascript" src="../../static/public_file/js/json2.js"></script>
    <script type="text/javascript" src="../../static/public_file/GooFlow/codebase/GooFlow.js"></script>
    <script type="text/javascript">

        function fromToJson(form) {
            var result = {};
            //获取表单的数组对象
            var fieldArray = $('#' + form).serializeArray();
            //将表单转化为JSON对象
            for (var i = 0; i < fieldArray.length; i++) {
                var field = fieldArray[i];
                if (field.name in result) {
                    result[field.name] += ',' + field.value;
                } else {
                    result[field.name] = field.value;
                }
            }
            return result;
        }

        var json_form = JSON.parse({{ form_data | safe }});

        var tag_name = "";
        var tag_type = "";
        var tag_placeholder = "";
        var label_name = "";
        var tag_id = "";
        var menu_from = document.getElementById("menu_from_1");


        for (var i=0; i<json_form["list"].length; i++) {
            if (json_form["list"][i]["compName"] === "栅格布局") {
                var div = document.createElement("div");
                div.style.padding = '1%';
                for (var t=0; t<json_form["list"][i]["columns"].length; t++) {
                    var div_tag = document.createElement("div");
                    div_tag.style.display = "inline-block";div_tag.style.width = "43%";
                    tag_name = json_form["list"][i]["columns"][t]["list"][0]["compIcon"];
                    tag_type = json_form["list"][i]["columns"][t]["list"][0]["viewType"];
                    tag_placeholder = json_form["list"][i]["columns"][t]["list"][0]["placeholder"];
                    tag_id = json_form["list"][i]["columns"][t]["list"][0]["id"];
                    label_name = json_form["list"][i]["columns"][t]["list"][0]["label"];

                    {#var tag_label = document.createElement(tag_name);#}
                    var label = document.createElement("label");
                    label.innerHTML = label_name;label.className = "label_tag";

                    create_tag(div_tag, tag_name, label);

                    div.appendChild(div_tag);
                    menu_from.appendChild(div)
                }
            }else {
                tag_name = json_form["list"][i]["compIcon"];
                tag_type = json_form["list"][i]["viewType"];
                tag_placeholder = json_form["list"][i]["placeholder"];
                tag_id = json_form["list"][i]["id"];
                label_name = json_form["list"][i]["label"];

                var div1 = document.createElement("div");
                div1.style.padding = '1%';

                var label1 = document.createElement("label");
                label1.innerHTML = label_name;label1.className = "label_tag";

                create_tag(div1, tag_name, label1);
            }
        }


        function create_tag(div1, tag_name, label1) {
            if (tag_name === "textarea"){
                textarea = create_textarea();
                textarea.className = "textarea-style";textarea.setAttribute("placeholder", tag_placeholder);
                div1.appendChild(label1);div1.appendChild(textarea);
                menu_from.appendChild(div1)
            }else if (tag_name === "att") {             // 多行文本框
                file = create_upfile();
                div1.appendChild(label1);div1.appendChild(file);
                {#div1.style.textAlign = "left";#}
                menu_from.appendChild(div1)
            }else if (tag_name === "input"){            // input标签
                var input_tag = create_input();
                input_tag.setAttribute("placeholder", tag_placeholder);
                div1.appendChild(label1);div1.appendChild(input_tag);
                menu_from.appendChild(div1);
            }else if (tag_name === "date"){         // 时间日期
                var date_tag = create_date();
                div1.appendChild(label1);div1.appendChild(date_tag);
                menu_from.appendChild(div1);
            }else if (tag_name === "divider"){          // 分割线
                var halving_line_tag = create_halving_line();
                menu_from.appendChild(halving_line_tag);
            }else if (tag_name === "select"){
                var select_tag = create_select();
                div1.appendChild(label1);div1.appendChild(select_tag);
                menu_from.appendChild(div1);
            }
        }


        function create_textarea() {
            var textarea = document.createElement("textarea"); //cols="30" rows="10"
            textarea.setAttribute("cols", "30");textarea.setAttribute("rows", "5");textarea.setAttribute("name", tag_id);textarea.setAttribute("id", tag_id);
            return textarea
        }

        function create_upfile() {
            var div = document.createElement("div");
            div.style.width = "80%";div.style.display = "inline-block";div.style.textAlign = "left";div.style.paddingLeft = "1%";
            var div1 = document.createElement("div");
            div1.innerHTML = '<a href="javascript:;" class="file"><i class="iconfont icon-upload"></i> 上传<input type="file" name="" id="signature_picture"></a>';

            div.appendChild(div1);
            return div
        }

        function create_input() {
            var input = document.createElement("input");
            input.className = "input-style";input.setAttribute("name", tag_id);input.setAttribute("id", tag_id);
            return input
        }

        function create_date() {
            var input = document.createElement("input");
            input.className = "input-style";input.setAttribute("type", "text");input.setAttribute("name", tag_id);input.setAttribute("id", tag_id);
            return input
        }

        function create_halving_line() {
            var div = document.createElement("div");
            div.className = "halving_line";
            return div
        }

        function create_select() {
            var vacation_list = ["事假", "病假", "婚假", "丧假", "产假", "探亲假", "年假", "公假"];
            var select = document.createElement("select");
            select.className = "input-style";select.setAttribute("name", tag_id);select.setAttribute("id", tag_id);
            for (var i=0; i<vacation_list.length; i++){
                var option = document.createElement("option");
                option.innerHTML = vacation_list[i];
                select.appendChild(option);
            }
            return select
        }

        var form_detail = {{ form_detail | safe }};

        if ('meeting_theme' in form_detail) {
             var key_list = ['proposer', 'department', 'create_time', 'file_list', 'form_name', 'form_url', 'form_id', 'diagram','meeting_theme','meeting_room','meeting_start','meeting_end','meeting_marks'];
                     for (var j=0; j<Object.keys(form_detail).length; j++){
            if (!key_list.includes(Object.keys(form_detail)[j])) {
                document.getElementById(Object.keys(form_detail)[j]).value = form_detail[Object.keys(form_detail)[j]];
            }
        }
        document.getElementById("form_name").innerText = form_detail["form_name"];
        document.getElementById("proposer").value = form_detail["proposer"];
        document.getElementById("now_time").value = form_detail["create_time"];
        document.getElementById("department").value = form_detail["department"];
        document.getElementById("fd_1634720733809").value = form_detail["meeting_theme"];
        document.getElementById("fd_1634720737814").value = form_detail["meeting_room"];
        document.getElementById("fd_1634720744521").value = form_detail["meeting_start"];
        document.getElementById("fd_1634720746314").value = form_detail["meeting_end"];
        document.getElementById("fd_1634720782248").value = form_detail["meeting_marks"];
        }
        else {
            var key_list = ['proposer', 'department', 'create_time', 'file_list', 'form_name', 'form_url', 'form_id', 'diagram'];
                    for (var j=0; j<Object.keys(form_detail).length; j++){
            if (!key_list.includes(Object.keys(form_detail)[j])) {
                document.getElementById(Object.keys(form_detail)[j]).value = form_detail[Object.keys(form_detail)[j]];
            }
        }
        document.getElementById("form_name").innerText = form_detail["form_name"];
        document.getElementById("proposer").value = form_detail["proposer"];
        document.getElementById("now_time").value = form_detail["create_time"];
        document.getElementById("department").value = form_detail["department"];

        }

        create_table1(form_detail["file_list"]);
        function create_table1(JsonDate) {
            var t_table = document.getElementById("t_table");
            for (var b=0; b<JsonDate.length; b++){
                var tr = document.createElement("tr");
                var td = document.createElement("td");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                td.innerHTML = "<input id='"+JsonDate["file_name"]+"' class='check_box' type=\"checkbox\">";td.style.textAlign = "center";
                td1.innerHTML = b+1;td1.style.textAlign = "center";
                td2.innerHTML = JsonDate[b]["file_name"];td2.style.paddingLeft = "1%";
                td3.innerHTML = JsonDate[b]["file_size"];td3.style.paddingLeft = "1%";
                td4.innerHTML = JsonDate[b]["up_time"];td4.style.textAlign = "center";
                var local_host = window.location.host;
                td6.innerHTML = "<a href='"+JsonDate["file_path"]+"'>下载</a>";td6.style.textAlign = "center";
                tr.appendChild(td);tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td6);
                t_table.appendChild(tr);
            }
        }

        const E = window.wangEditor;
        const editor = new E("#summernote");
        // 或者 const editor = new E(document.getElementById('div1'))
        editor.config.uploadImgShowBase64 = 'true';
        editor.placeholder = "qin";
        editor.create();
    </script>
{% endblock %}
